package wetalk.software.bupt.com.wetalk.BroadcastReceiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.google.gson.Gson;

import wetalk.software.bupt.com.wetalk.DB.WeTalkDB;
import wetalk.software.bupt.com.wetalk.application.MyApplication;
import wetalk.software.bupt.com.wetalk.model.po.Applicant;
import wetalk.software.bupt.com.wetalk.view.activity.MainActivity;

public class NewFriendReceiver extends BroadcastReceiver {
    private static final String TAG="NewFriendReceiver";
    @Override
    public void onReceive(Context context, Intent intent) {
        String content=intent.getStringExtra("content");
        Log.d(TAG,"onReceive"+content);
        Applicant applicant=new Gson().fromJson(content,Applicant.class);
        applicant.setStatus(0);
        if(WeTalkDB.create(MyApplication.getContext()).queryApplicant(applicant.getId())==null){
            WeTalkDB.create(MyApplication.getContext()).addApplicant(applicant);
        }else{
            WeTalkDB.create(MyApplication.getContext()).queryApplicant(applicant.getId()).setStatus(0);
        }
    }
}
